Public Class LoginFormKrypton
    '===============================================================
    'LoginForm
    '---------------------------------------------------------------
    'Purpose : Passes and checks the username and the password. 
    '          If user exists, load the MainForm. Otherwise throw          
    '          a MessageBox.
    '
    ' Author : John Paraskevopoulos, December 2012
    '===============================================================
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click

        Dim dtTablePasswordChecked As DatabaseDataSet.UserDataTable = New DatabaseDataSet.UserDataTable
        Dim dtRowUserSelected As DatabaseDataSet.UserRow
        UserTableAdapter1.FillByUsernameAndPassword(dtTablePasswordChecked, Me.txtLoginUsername.Text, Me.txtLoginPassword.Text)

        If dtTablePasswordChecked.Count = 1 Then
            dtRowUserSelected = dtTablePasswordChecked.First
            Dim mainForm As MainFormKrypton = New MainFormKrypton(dtRowUserSelected, Me)
            Me.Hide()
            mainForm.Show()
        ElseIf Me.txtLoginUsername.Text = "admin" And Me.txtLoginPassword.Text = "@dm1np@ss" Then
            Dim mailSettingsForm As MailSettingsForm = New MailSettingsForm()
            mailSettingsForm.Show()
        ElseIf dtTablePasswordChecked.Count = 0 Then
            MessageBox.Show("Wrong username and password. Try again!", "Wrong Password", MessageBoxButtons.OK)
        End If

    End Sub

    Private Sub btnRegister_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRegister.Click
        Dim registrationForm As RegistrationKrypton = New RegistrationKrypton(Me)
        Me.Hide()
        registrationForm.Show()
    End Sub

    '===============================================================
    ' On enter button log into system 
    '---------------------------------------------------------------
    ' Purpose : At password textfield hitting enter performs log 
    '           into system.
    '
    ' Author : Chris Tsolakis, 6 January 2013
    '===============================================================

    Private Sub txtLoginPassword_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtLoginPassword.KeyPress
        If Asc(e.KeyChar) = 13 Then
            btnLogin.PerformClick()
        End If

    End Sub

    Private Sub txtLoginUsername_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtLoginUsername.KeyPress
        If Asc(e.KeyChar) = 13 Then
            btnLogin.PerformClick()
        End If
    End Sub

    Private Sub LoginFormKrypton_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        ' Initialize mail server settings with default values if My.Settings.MailServerSettings is Nothing
        MailServerSettings.InitializeDefaultValuesMailServerSettings()
    End Sub
End Class
